import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:interview_success_flutter/components/my_app_bar.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:interview_success_flutter/components/my_indicator.dart';

class DeviceStoragePage extends StatefulWidget {
  const DeviceStoragePage({super.key});

  @override
  State<DeviceStoragePage> createState() => _DeviceStoragePageState();
}

class _DeviceStoragePageState extends State<DeviceStoragePage> {
  String url = '';

  final _platform = const MethodChannel('xyz.zhousg.interview_success_project');

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const MyAppBar(
        title: '设备空间',
      ),
      body: Column(
        children: [
          TextButton(
            onPressed: () {
              _platform.invokeMethod('openCamera').then(
                    (value) => setState(() {
                      url = value;
                    }),
                  );
            },
            child: Text('打开相机$url'),
          ),
          TextButton(
            onPressed: () {
              Map<String, String> data = {'name': 'jack'};
              BoostChannel.instance.sendEventToNative('updateUser', data);
            },
            child: const Text('发送消息'),
          ),
          Expanded(
            child: PieChart(
              PieChartData(
                borderData: FlBorderData(
                  show: false,
                ),
                sectionsSpace: 0,
                centerSpaceRadius: 60,
                sections: [
                  PieChartSectionData(
                    color: const Color(0xffbbbbbb),
                    value: 50,
                    title: '剩余可用',
                    radius: 50,
                    titleStyle: const TextStyle(
                      fontSize: 10.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.white,
                    ),
                  ),
                  PieChartSectionData(
                    color: const Color(0xff3266EE),
                    value: 40,
                    title: '其他APP占用',
                    radius: 50,
                    titleStyle: const TextStyle(
                      fontSize: 10.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.white,
                    ),
                  ),
                  PieChartSectionData(
                    color: const Color(0xfffa6d1d),
                    value: 10,
                    title: '面通已用',
                    radius: 50,
                    titleStyle: const TextStyle(
                      fontSize: 10.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.white,
                    ),
                  ),
                ],
              ),
              // read about it in the PieChartData section
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(50),
            child: Column(
              children: const [
                MyIndicator(
                  color: Color(0xfffa6d1d),
                  text: '面试通',
                  isSquare: true,
                ),
                SizedBox(
                  height: 6,
                ),
                MyIndicator(
                  color: Color(0xff3266EE),
                  text: '其他APP',
                  isSquare: true,
                ),
                SizedBox(
                  height: 6,
                ),
                MyIndicator(
                  color: Color(0xffbbbbbb),
                  text: '剩余可用',
                  isSquare: true,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
